#pragma once

#include <afx.h>

#include <stack>
#include <list>
#include <map>

#include "Program.h"
#include "Error.h"

#define MAX_LINE_LENGTH 256
#define KEYWORD_GLOBAL "global"
#define FILE_EXTENSION ".ssl"	// ship scripting language

using namespace std;

class CLanguage
{
public:
	CLanguage(CString file);
	CLanguage();
	~CLanguage();

	bool ParseParen();
	bool ParseParenFile(CString fileName);
	bool AddFile(CString fileName);
	CProgram getProgram();
	bool Parse();
	bool ReadFiles();
	bool ReadFile(CString fileName);

	bool ParseGlobals(CString fileName);
	bool ParseFunctions(CString fileName);
	bool ParseStatements(CString fileName);
	bool ParseGlobalLine(CString line);

	list<CString> getFileNames();
	map<CString, list<CString>> getFileLines();
	CError getErrors();

	void AddFileName(CString fileName);

	list<CString> SplitString(CString str);
private:
	stack<char> m_BraceStack;
	list<CString> m_FileNames;
	list<CString> m_Types;	// To make adding new types easier
	map<CString, list<CString>> m_Lines;
	CProgram m_Program;
	CError m_Errors;

	bool InsideFunction(CString line);
	void InitTypes();
};